package nowcoder.offer;

import company.Ali.A;

/**
 * 不用加减乘除做加法
 *
 * @author briarbear
 * @blog https://briarbear.github.io
 * @date 2018-08-28 16:39
 */
public class Add {
    public int solution(int num1,int num2){
        int sum,carry;
        do{
            sum = num1 ^ num2; //异或 计算的为各位相加的结果
            carry = (num1 & num2) << 1;  //与 移位运算
            num1 = sum;
            num2 = carry;
        }while (num2 != 0);

        return num1;
    }

    public static void main(String[] args) {
        new Add().solution(4,6);
    }
}
